<?php

/**
 * FileName: InfoController.php
 * Author: @163.com
 * DateTime: 2023-02-21 下午 09:54
 * Summary:
 */


namespace App\Http\Controllers\Api\User;


use App\Http\Controllers\Api\BasicController;
use App\Models\Divination\Divination;
use App\Models\Dynamic\Lists;
use App\Models\OrderAppoint;
use App\Models\SiteCode;
use App\Models\User;
use App\Models\UserInfo;
use App\Services\Sms;
use Carbon\Carbon;
use GatewayWorker\Lib\Gateway;
use Jiannei\Response\Laravel\Support\Facades\Response;

class MyController extends BasicController
{

    /**
     * @api {get} /user/info/basic  基础信息
     * @apiName UserInfoBasic
     * @apiGroup UserInfo
     * @apiDescription 基础信息
     *
     * @apiHeader {String} Authorization='Bearer '
     */
    public function basic()
    {
        $uid = $this->uid();
        $result = (new User())->getUser(['id'=>$uid]);
        if($result->extend){
            $result->extend->comment_num=OrderAppoint::where(['appoint_id'=>$uid,'status'=>5])->count();
            $result->extend->post_num=Lists::where(['user_id'=>$uid])->count();
        }
        return Response::success($result);
    }

    /**
     * @api {post} /user/info  基础信息
     * @apiName UserInfoBasic
     * @apiGroup UserInfo
     * @apiDescription 基础信息
     *
     * @apiHeader {String} Authorization='Bearer '
     */
    public function quizes()
    {
        $uid = $this->uid();
        $result=Divination::where(['uid'=>$uid])->orderByDesc('id')->paginate();
        return Response::success($result);
    }


    public function orders(){
        $uid = $this->uid();
        $result=OrderAppoint::where(['user_id'=>$uid])->where('status','>',3)
            ->with(['teacher'=>function($query){
                $query->select(['id','name','avatar']);
            }])
            ->orderByDesc('id')
            ->paginate();
        foreach ($result as $item){
            $item->call_time=0;
            if($item->end_time)
            $item->call_time=Carbon::parse($item->begin_time)->diffInSeconds(Carbon::parse($item->end_time));
        }
        return Response::success($result);
    }




}
